package com.chinasoft.mall.framework;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.util.Log;

import com.chinasoft.mall.activity.MainActivity;
import com.chinasoft.mall.activity.StaffLoginActivity;
import com.chinasoft.mall.activity.WidgetActivity;
import com.chinasoft.mall.model.BaseBean;
import com.chinasoft.mall.model.FormFile;
import com.chinasoft.mall.model.UploadBean;
import com.chinasoft.mall.model.response.BaseResponse;
import com.chinasoft.mall.model.response.EmployeeGoodsByClass;
import com.chinasoft.mall.model.response.EpgBean;
import com.chinasoft.mall.model.response.GetGameBean;
import com.chinasoft.mall.model.response.GetGameBean.Data;
import com.chinasoft.mall.model.response.GetGoodGrpImgByIdBean;
import com.chinasoft.mall.model.response.GetStartImgBean;
import com.chinasoft.mall.model.response.GoodsByClassBean;
import com.chinasoft.mall.model.response.GoodsByClassEmployeeBean;
import com.chinasoft.mall.model.response.GoodsClassBean;
import com.chinasoft.mall.model.response.GoodsGrpBean;
import com.chinasoft.mall.model.response.GoodsImgBean;
import com.chinasoft.mall.model.response.LoginCheckBean;
import com.chinasoft.mall.model.response.ModelWeiboBean;
import com.chinasoft.mall.model.response.ModellistBean;
import com.chinasoft.mall.model.response.PushMessageBean;
import com.chinasoft.mall.model.response.RechnBean;
import com.chinasoft.mall.model.response.SearchGoodsBean;
import com.chinasoft.mall.model.response.TopicBean;
import com.chinasoft.mall.receiver.myBroadCast;
import com.chinasoft.mall.util.SystemSetting;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

/**
 * 事务处理器
 * 
 * @author Administrator
 * 
 */
public class Processor implements DialogInterface.OnCancelListener {
	private RequestProcessing rp = RequestProcessing.getInstance();
	private BlockingQueue<BaseBean> tms = new ArrayBlockingQueue<BaseBean>(100);
	private static ExecutorService service = Executors.newFixedThreadPool(100);
	private static Processor p = new Processor();
	private Thread t;
	private int processorId = 0;

	private Processor() {
//		if (t == null) {
//			t = new Thread(this);
//		}
//		t.start();
	};

	public static Processor getInstance() {
		return p;
	}

	public void handlePushMessage(BaseBean _tm,Context context){
//		Intent intent = new Intent();
//		intent.setClass(context, WidgetActivity.class);
//		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		// context.startActivity(intent);
		Log.e("handlePushMessage", "handlePushMessage=========");
		BaseBean baseRes = _tm;
		BaseResponse _br = null;
		String resMessage = null;
		String classpath = null;
		try {
			String reqMessage = addProperties(_tm.getReq_Dateurl(), _tm.reqData);
			Log.i("pushmessage", "请求 Message:" + reqMessage);
			resMessage = rp.requesturl(reqMessage);
			 Log.i("pushmessage", "返回 Message:" + resMessage);
			classpath = Config.KVCLAZZ.get(_tm.getReq_url());
			_br = new BaseResponse(classpath);

			if (resMessage != null) {
				int jsontype = _br.getJsonType();
				if (jsontype == 0) {
					_br.setData(HttpJsonAdapter.getInstance().get(resMessage,
							_br.getBeanClass(classpath)));
				} else if (jsontype == 1) {
					Gson gson = new GsonBuilder().setDateFormat(
							"yyyy-MM-dd HH:mm:ss").create();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		baseRes.setResData(_br);
		
			Log.i("BROADCAST_TAG", "匹配数据//;");
			if (Config.GET_GAME.equals(baseRes
					.getReq_url())) {
				if (baseRes.getResData() != null
						&& baseRes.getResData().getData() != null) {
					GetGameBean _ggb = ((GetGameBean) baseRes
							.getResData().getData());
					List<Data> lds = _ggb.getDatas();
					EpgBean _eb = new EpgBean();
					if (_ggb.getContent() != null
							&& !"".equals(_ggb.getContent())
							&& !OrderGoods.prompt_bg.contains(_ggb
									.getContent())) {
						_eb.setTHUM(_ggb.getContent());
						OrderGoods.prompt_bg.add(_ggb.getContent());
						Intent intent = new Intent(
								myBroadCast.ACTION_INTENT_TEST);
						intent.putExtra(Config.INTENT_OBJ, _eb);
						context.sendBroadcast(intent);
					}
					if (lds != null && lds.size() > 0) {
						for (Data d : lds) {
							if (!OrderGoods.goodsids_bg.contains(d)) {
								OrderGoods.goodsids_bg.add(d);
//								OrderGoods.isCancle = true;
								_eb.setGOODS_NAME(d.getGoodsName());
								_eb.setBiType((byte) 1);
								Intent intent = new Intent(
										myBroadCast.ACTION_INTENT_TEST);
								intent.putExtra(Config.INTENT_OBJ, _eb);
								context.sendBroadcast(intent);
								break;
							}
						}
					}
				}

			}
//		if (Config.GET_GAME.equals(baseRes.getReq_url())) {
//			if (baseRes.getResData() != null && baseRes.getResData().getData() != null) {
//				GetGameBean _ggb = (GetGameBean) baseRes.getResData().getData();
//				EpgBean _eb = new EpgBean();
//				if (_ggb.getContent() != null && !"".equals(_ggb.getContent())
//						&& !OrderGoods.prompt_bg.contains(_ggb.getContent())) {
//					_eb.setTHUM(_ggb.getContent());
//					OrderGoods.prompt_bg.add(_ggb.getContent());
//					// Date d = new Date(System.currentTimeMillis());
//					Log.e("tag", "弹出窗口=======");
//					Intent intent = new Intent();
//					intent.setClass(context, WidgetActivity.class);
//					intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//					context.startActivity(intent);             
//				}
//				List<Data> lds = _ggb.getDatas();
//				if (lds != null && lds.size() > 0
//						) {
//					for (Data d : lds) {
//						if ("yyl".equals(d.getType())
//								&& !OrderGoods.goodsids.contains(d)) {
////							((MainActivity) this.getParent()).showGame(d);
//							break;
//						}
//					}
//				}
//			}
//		} else if (Config.STARTIMG.equals(baseRes.getReq_url())) {
//			if (baseRes.getResData() != null && baseRes.getResData().getData() != null) {
//
//			}
//		} else if(Config.GET_MESSAGE.equals(baseRes.getReq_url())){
//			GetGameBean _ggb = (GetGameBean) baseRes.getResData().getData();
//			if(null == _ggb){
//				return;
//			}
//			List<Data> lds = _ggb.getDatas();
//			if (lds != null && lds.size() > 0//&& this.getParent() instanceof MainActivity
//					) {
//				for (Data d : lds) {
//					if ("yyl".equals(d.getType())
//							&& !OrderGoods.goodsids.contains(d)) {
////						((MainActivity) this.getParent()).showGame(d);
//						break;
//					}
//				}
//			}
//		}
	}
	public void startMission(BaseBean tm) {
//		try {
//			tms.put(tm);
//		} catch (InterruptedException e) {
//			e.printStackTrace();
//		}
		final BaseBean _tm = tm;
		service.execute(new Runnable() {
			
			@Override
			public void run() {
//				BaseBean _tm = null;
//				try {
//					_tm = tms.take();
//				} catch (InterruptedException e) {
//					e.printStackTrace();
//				}
//				_tm.setProcessorId(processorId++);
				if (_tm != null) {
					switch (_tm.getReq_type()) {
					// get
					case 1:
						QueueMethod(_tm);
						break;
					// post
					case 2:
						break;
					// xml
					case 3:
						break;
					// 上传图片
					case 4:
						UploadMethod(_tm);
						break;
					case 5:
						QueueQuery(_tm);
						break;
					default:
						QueueMethod(_tm);
						break;
					}
				}
			}
		});
	}
	
	/**
	 * 上传请求
	 * 
	 * @param _tm
	 *            消息头
	 */
	private void UploadMethod(BaseBean _tm) {
		UploadBean _upload = (UploadBean) _tm;
		FormFile formFile = new FormFile(UUID.randomUUID() + ".jpg",
				_upload.getData(), "imagefile", "image/gif");
		String reqMessage;
		try {
			reqMessage = addProperties(_tm.getReq_url(), _tm.reqData);
			Log.i("processor", "请求 Message:" + reqMessage);
			Map<String, String> maps = new HashMap<String, String>();
			if (SocketHttpRequester.post(reqMessage, maps, formFile)) {
				if (maps.get("jsondata") != null) {
					_upload = HttpJsonAdapter.getInstance().get(
							maps.get("jsondata").trim(), UploadBean.class);
				}
			}
			_tm.getRc().Centercall(_upload);
		} catch (Exception e) {
			e.printStackTrace();
			_tm.getRc().Centercall(_upload);
		}
	}

	private void QueueQuery(BaseBean _tm) {
		BaseBean baseRes = _tm;
		try {
			if (_tm.getPageBean() != null && _tm.getPageBean().isNextPage()) {
				_tm.getPageBean().nextPage(_tm.reqData);
			}

			LinkedList<BasicNameValuePair> params = new LinkedList<BasicNameValuePair>();
			params.add(new BasicNameValuePair(StaffLoginActivity.USER_NAME,
					_tm.reqData.get(StaffLoginActivity.USER_NAME)));
			params.add(new BasicNameValuePair(StaffLoginActivity.USER_NO,
					_tm.reqData.get(StaffLoginActivity.USER_NO)));

			HttpClient httpClient = new DefaultHttpClient();
			HttpPost postMethod = new HttpPost(_tm.getReq_Dateurl());
			postMethod.setEntity(new UrlEncodedFormEntity(params, "utf-8")); // 将参数填入POST
																				// Entity中

			HttpResponse response = httpClient.execute(postMethod); // 执行POST方法
			// Log.i(TAG, "resCode = " +
			// response.getStatusLine().getStatusCode()); //获取响应码
			// Log.i(TAG, "result = " +
			// EntityUtils.toString(response.getEntity(), "utf-8")); //获取响应内容

			// String reqMessage = addProperties(_tm.getReq_Dateurl(),
			// _tm.reqData);
			// Log.i("processor", "请求 Message:" + reqMessage);
			String resMessage = EntityUtils.toString(response.getEntity(),
					"utf-8");
			String classpath = Config.KVCLAZZ.get(_tm.getReq_url());
			BaseResponse _br = new BaseResponse(classpath);
			if (resMessage != null) {
				int jsontype = _br.getJsonType();
				if (jsontype == 0) {
					_br.setData(HttpJsonAdapter.getInstance().get(resMessage,
							_br.getBeanClass(classpath)));
				} else if (jsontype == 1) {
					Gson gson = new GsonBuilder().setDateFormat(
							"yyyy-MM-dd HH:mm:ss").create();
					if (_tm.getReq_url().equals(Config.GET_RECHN)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<RechnBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.GET_EPG)) {
						// 节目单
						List<EpgBean> _ebs = gson.fromJson(resMessage,
								new TypeToken<List<EpgBean>>() {
								}.getType());
						_br.setData(_ebs);
						for (EpgBean _eb : _ebs) {
							if (SystemSetting.goodsids.contains(_eb
									.getGOODS_ID())) {
								_eb.setNotify(true);
							}
						}
						// 选取当天的数据
						LivingGoods.getInstance().setEpgBeans(_ebs);
					} else if (_tm.getReq_url().equals(Config.GET_EPG_PRE)) {
						// 节目单
						List<EpgBean> _ebs = gson.fromJson(resMessage,
								new TypeToken<List<EpgBean>>() {
								}.getType());
						for (EpgBean _eb : _ebs) {
							if (SystemSetting.goodsids.contains(_eb
									.getGOODS_ID())) {
								_eb.setNotify(true);
							}
							_eb.setLivingState((byte) 1);
						}
						_br.setData(_ebs);
					} else if (_tm.getReq_url().equals(Config.GET_EPG_NEXT)) {
						// 节目单
						List<EpgBean> _ebs = gson.fromJson(resMessage,
								new TypeToken<List<EpgBean>>() {
								}.getType());
						for (EpgBean _eb : _ebs) {
							if (SystemSetting.goodsids.contains(_eb
									.getGOODS_ID())) {
								_eb.setNotify(true);
							}
							_eb.setLivingState((byte) -1);
						}
						_br.setData(_ebs);
					} else if (_tm.getReq_url().equals(Config.GET_GOODSCLASS)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<GoodsClassBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.GET_GOODSBYCLASS)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<GoodsByClassBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.GET_GOODSBYID)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<GoodsByClassBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(
							Config.GET_GOODSGRPIMGBYID)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<GetGoodGrpImgByIdBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.GET_GOODSGRP)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<GoodsGrpBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.GET_GOODSIMG)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<GoodsImgBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.GET_MODELWEIBO)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<ModelWeiboBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.SEACH_GOODS)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<SearchGoodsBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.GET_MODELLIST)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<ModellistBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.GET_URL)) {
						if (resMessage != null && !"".equals(resMessage.trim())) {
							Config.BASE_URL = resMessage.trim();
						}
					} else if (_tm.getReq_url().equals(Config.STARTIMG)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<GetStartImgBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.LOGIN_CHECK)) {
						_br.setData(gson.fromJson(resMessage,
								LoginCheckBean.class));
					}
				} else if (jsontype == 2) {
					Gson gson = new GsonBuilder().setDateFormat(
							"yyyy-MM-dd HH:mm:ss").create();
					if (_tm.getReq_url().equals(Config.GET_RECI)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<String>>() {
								}.getType()));
					}
				}
			}
			baseRes.setResData(_br);
			if (_tm.getProcessorId() > processorId) {
				return;
			}
			_tm.getRc().Centercall(baseRes);
		} catch (Exception e) {
			e.printStackTrace();
			if (_tm.getProcessorId() > processorId) {
				return;
			}
			_tm.getRc().Centercall(baseRes);
		}
	}

	private void QueueMethod(BaseBean _tm) {
		BaseBean baseRes = _tm;
		try {
			if (_tm.getPageBean() != null && _tm.getPageBean().isNextPage()) {
				_tm.getPageBean().nextPage(_tm.reqData);
			}
			String reqMessage = addProperties(_tm.getReq_Dateurl(), _tm.reqData);
			Log.i("processor", "请求 Message:" + reqMessage);
			String resMessage = rp.requesturl(reqMessage);
			if (_tm.getReq_url().equals(Config.GET_EPG)) {
				Log.i("processor", "返回 Message JMD ========:" + resMessage);
			}
			String classpath = Config.KVCLAZZ.get(_tm.getReq_url());
			BaseResponse _br = new BaseResponse(classpath);
			if (resMessage != null) {
				int jsontype = _br.getJsonType();
				if (jsontype == 0) {
					_br.setData(HttpJsonAdapter.getInstance().get(resMessage,
							_br.getBeanClass(classpath)));
				} else if (jsontype == 1) {
					Gson gson = new GsonBuilder().setDateFormat(
							"yyyy-MM-dd HH:mm:ss").create();
					if (_tm.getReq_url().equals(Config.GET_RECHN)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<RechnBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.GET_EPG)) {
						// 节目单
						List<EpgBean> _ebs = gson.fromJson(resMessage,
								new TypeToken<List<EpgBean>>() {
								}.getType());
						_br.setData(_ebs);
						for (EpgBean _eb : _ebs) {
							if (SystemSetting.goodsids.contains(_eb
									.getGOODS_ID())) {
								_eb.setNotify(true);
							}
						}
						// 选取当天的数据
						LivingGoods.getInstance().setEpgBeans(_ebs);
					} else if (_tm.getReq_url().equals(Config.GET_EPG_PRE)) {
						// 节目单
						List<EpgBean> _ebs = gson.fromJson(resMessage,
								new TypeToken<List<EpgBean>>() {
								}.getType());
						for (EpgBean _eb : _ebs) {
							if (SystemSetting.goodsids.contains(_eb
									.getGOODS_ID())) {
								_eb.setNotify(true);
							}
							_eb.setLivingState((byte) 1);
						}
						_br.setData(_ebs);
					} else if (_tm.getReq_url().equals(Config.GET_EPG_NEXT)) {
						// 节目单
						List<EpgBean> _ebs = gson.fromJson(resMessage,
								new TypeToken<List<EpgBean>>() {
								}.getType());
						for (EpgBean _eb : _ebs) {
							if (SystemSetting.goodsids.contains(_eb
									.getGOODS_ID())) {
								_eb.setNotify(true);
							}
							_eb.setLivingState((byte) -1);
						}
						_br.setData(_ebs);
					} else if (_tm.getReq_url().equals(Config.GET_GOODSCLASS)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<GoodsClassBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.GET_GOODSBYCLASS)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<GoodsByClassBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(
							Config.GET_GOODSBYCLASSID)) {
						_br.setData(gson
								.fromJson(
										resMessage,
										new TypeToken<List<EmployeeGoodsByClass>>() {
										}.getType()));
					} else if (_tm.getReq_url().equals(
							Config.GET_GOODSBYTPID)) {
						_br.setData(gson
								.fromJson(
										resMessage,
										new TypeToken<List<EmployeeGoodsByClass>>() {
										}.getType()));
					} else if (_tm.getReq_url().equals(
							Config.EMPLYEE_GOODS_CLASS)) {
						_br.setData(gson
								.fromJson(
										resMessage,
										new TypeToken<List<GoodsByClassEmployeeBean>>() {
										}.getType()));
					} else if (_tm.getReq_url().equals(
							Config.EMPLOYEE_GOODS_TOPIC)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<TopicBean>>() {
								}.getType()));
					}
					else if (_tm.getReq_url().equals(Config.GET_GOODSBYID)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<GoodsByClassBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(
							Config.GET_GOODSGRPIMGBYID)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<GetGoodGrpImgByIdBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.GET_GOODSGRP)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<GoodsGrpBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.GET_GOODSIMG)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<GoodsImgBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.GET_MODELWEIBO)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<ModelWeiboBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.SEACH_GOODS)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<SearchGoodsBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.GET_MODELLIST)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<ModellistBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.GET_URL)) {
						if (resMessage != null && !"".equals(resMessage.trim())) {
							Config.BASE_URL = resMessage.trim();
						}
					} else if (_tm.getReq_url().equals(Config.STARTIMG)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<GetStartImgBean>>() {
								}.getType()));
					} else if (_tm.getReq_url().equals(Config.LOGIN_CHECK)) {
						_br.setData(gson.fromJson(resMessage,
								LoginCheckBean.class));
					} else if (_tm.getReq_url().equals(Config.PUSH_MESSAGE)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<PushMessageBean>>() {
								}.getType()));
					}
				} else if (jsontype == 2) {
					Gson gson = new GsonBuilder().setDateFormat(
							"yyyy-MM-dd HH:mm:ss").create();
					if (_tm.getReq_url().equals(Config.GET_RECI)) {
						_br.setData(gson.fromJson(resMessage,
								new TypeToken<List<String>>() {
								}.getType()));
					}
				}
			}
			baseRes.setResData(_br);
			if (_tm.getProcessorId() > processorId) {
				return;
			}
			_tm.getRc().Centercall(baseRes);
		} catch (Exception e) {
			e.printStackTrace();
			if (_tm.getProcessorId() > processorId) {
				return;
			}
			_tm.getRc().Centercall(baseRes);
		}
	}

	public static String addProperties(String url,
			HashMap<String, String> reqdatas) throws IllegalArgumentException,
			IllegalAccessException, UnsupportedEncodingException {
		StringBuilder sb = new StringBuilder(url);
		if (url.contains("?")) {
			sb.append("&");
		} else {
			sb.append("?");
		}
		Set<Entry<String, String>> rqs = reqdatas.entrySet();
		Iterator<Entry<String, String>> iess = rqs.iterator();
		while (iess.hasNext()) {
			Entry<String, String> ess = iess.next();
			sb.append(URLEncoder.encode(ess.getKey(), "utf-8")).append("=")
					.append(URLEncoder.encode(ess.getValue(), "utf-8"))
					.append("&");
		}
		sb.deleteCharAt(sb.length() - 1);
		return sb.toString();
	}

	@Override
	public void onCancel(DialogInterface dialog) {
		tms.clear();
		processorId = 0;
		Log.i("tag", "--------------------清空数据-----------------------");
	}
}
